﻿Imports System.Data.SqlClient

Public Class frmThemPhieuNhapKho
    Dim dp As New DataProvider
    Dim mh As New CMatHang
    Dim pn As CPhieuNhap
    Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
        Dim cmd As New SqlCommand
        cmd.Connection = dp.con
        dp.OpenConnect()
        pn = New CPhieuNhap
        pn.MaNhanVien = Integer.Parse(txtMaNV.Text)
        pn.NgayNhap = dtpNgayNhap.Text

        Try
            Dim index As Integer = dgvCTPhieuNhap.Rows.Count - 2
            For i As Integer = index To 0 Step -1
                mh.TenMH = dgvCTPhieuNhap.Rows(i).Cells(0).Value.ToString()
                mh.Loai = dgvCTPhieuNhap.Rows(i).Cells(1).Value.ToString()
                mh.Gia = Single.Parse(dgvCTPhieuNhap.Rows(i).Cells(2).Value.ToString())
                mh.SoLuong = Integer.Parse(dgvCTPhieuNhap.Rows(i).Cells(5).Value.ToString())
                mh.XuatXu = dgvCTPhieuNhap.Rows(i).Cells(3).Value.ToString()
                mh.DonVi = dgvCTPhieuNhap.Rows(i).Cells(4).Value.ToString()
                CPhieuNhap.Insert(pn, mh)
            Next
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.MsgBoxHelp, "Error")
        Finally
            dp.CloseConnect()
        End Try
    End Sub
End Class